/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package FiveInARow;

import java.awt.*;
import java.awt.event.*;
import javax.swing.JPanel;

/**
 *
 * @author houfukude
 */
class MyJPanel extends Panel implements MouseListener{
    int BoW = 1;
    MyJPanel(){
        setSize(440,440);
        setLayout(null);
        setBackground(Color.green);
        addMouseListener(this);
    }



    @Override
    public   void   paint(Graphics   g)                    //绘制围棋棋盘的外观。
    {
        for(int i = 40 ; i <= 380 ;i = i + 20)
        {
            g.drawLine(40,i,400,i);
        }
        g.drawLine(40,400,400,400);
        for(int j = 40 ; j <= 380 ;j = j + 20)
        {
            g.drawLine(j,40,j,400);
        }
        g.drawLine(400,40,400,400);
        g.fillOval(97,97,6,6);
        g.fillOval(337,97,6,6);
        g.fillOval(97,337,6,6);
        g.fillOval(337,337,6,6);
        g.fillOval(217,217,6,6);
        
        
      }

    

    public void mouseClicked(MouseEvent e) {
        //throw new UnsupportedOperationException("Not supported yet.");
    }

    public void mousePressed(MouseEvent e) {
        //throw new UnsupportedOperationException("Not supported yet.");
        if(e.getModifiers()==InputEvent.BUTTON1_MASK)
          {
             One one = new One();
             int x=(int)e.getX();
             int y=(int)e.getY();       //获取按下鼠标时的坐标位置。
             int x1 = ( x + 10)/20;
             int y1 = ( y + 10)/20;
             
            if(x/20<2||y/20<2||x/20>19||y/20>19)     //棋盘以外不下棋子。
                    {}
            else{
                  if(BoW==1)                      //当棋子颜色是1时下黑棋子。
                  {

                      one.Bow = BoW;
                      one.setBounds(x1*20-7,y1*20-7,16,16);

                      BoW=BoW*(-1);
                      //tf2.setText("请白棋下子");
                      //tf1.setText("");
                  }
                  else
                      if(BoW==-1)                //当棋子颜色是-1时下白棋子。
                      {

                          BoW=BoW*(-1);
                          //tf1.setText("请黑棋下子");
                          //tf2.setText("");
                      }
                  }
             System.out.println("x = " + x1 + " y = " + y1);
          }
    }

    public void mouseReleased(MouseEvent e) {
        //throw new UnsupportedOperationException("Not supported yet.");
    }

    public void mouseEntered(MouseEvent e) {
        //throw new UnsupportedOperationException("Not supported yet.");
    }

    public void mouseExited(MouseEvent e) {
        //throw new UnsupportedOperationException("Not supported yet.");
    }
   
}
